﻿
namespace CmdArgs
{
    using System.Collections.Generic;
    using System.Linq;
    using CmdArgs.Settings;
    using CmdArgs.Validation;

    /// <summary>
    /// Represents on parsed option with it's values and 
    /// settings as object of <see cref="OptionSettings"/>.
    /// </summary>
    /// <remarks>
    /// Option may have no value or one or more values. 
    /// This can be checked using bool property <see cref="HasAnyValue"/>.
    /// Single value may be accessed via property <see cref="Value"/> 
    /// and all values may be accessed via property <see cref="Values"/>.
    /// </remarks>
    public sealed class Option
    {
        internal Option(IEnumerable<string> values, OptionSettings settings)
        {
            var newValues = new List<OptionParameterValue>();
            foreach (var value in values)
            {
                newValues.Add(new OptionParameterValue(value));
            }

            this.Values = newValues;
            this.Settings = settings;
        }

        internal Option(IEnumerable<string> values)
            : this(values, null)
        {
        }

        internal Option()
            : this(new string[0], null)
	    {
	    }

        internal Option(OptionSettings settings)
            : this(new string[0], settings)
        {
        }

        /// <summary>
        /// Gets the settings that blong to the option.
        /// </summary>
        public OptionSettings Settings { get; private set; }

        /// <summary>
        /// Gets the values of the option.
        /// This list contains <see cref="Value"/> as a first element.
        /// </summary>
        public IEnumerable<OptionParameterValue> Values { get; private set; }

        /// <summary>
        /// Gets the first value from collection <see cref="Values"/>.
        /// This is useful when the option has only one value and user knows it.
        /// </summary>
        public OptionParameterValue Value
        {
            get { return this.Values.First(); }
        }

        /// <summary>
        /// Gets a value indicating whether the option has any parameter value.
        /// </summary>
        public bool HasAnyValue
        {
            get { return this.Values.Any(); }
        }
    }
}
